<?php require_once 'header.php';?>    
<!-- DataTables Responsive CSS -->
    <link href="sb2/vendor/datatables-responsive/dataTables.responsive.css" rel="stylesheet">

        <!-- Page Content -->
        <div id="page-wrapper">
            <div class="container-fluid">
                <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <?php echo XXF_LNAME?><br>
                            
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <?php if(!$result){?>
                            	当前没有需要上传的成绩
                            <?php }else{?>
                            <?php echo $result['term']?> <?php echo $result['kname']?><br><br>
                            第一步：选择需要上传成绩的班级 
                            <select id="cid">
                            	<option>请选择</option>
                            	<?php 
                            	$class=xdb::getInstance()->getarray("select * from temstuclass where status !=0");
                            	foreach ($class as $row){
                            	?>
                            	<option value="<?php echo $row['id']?>"><?php echo $row['cname']?></option>
                            	<?php 
                            	}
                            	?>
                            	
                            </select>
                            <br><br>
                            第二步：选择需要上传成绩的课程
                            <select id="kcid">
                            	<option>请选择</option>
                            	<?php 
                            	$class=xdb::getInstance()->getarray("select * from kecheng where id>44 ");
                            	foreach ($class as $row){
                            	?>
                            	<option value="<?php echo $row['id']?>"><?php echo $row['kcname']?></option>
                            	<?php 
                            	}
                            	?>
                            </select>
                            <br><br>
                            第三步：下载《<input type="button" value="成绩模板" onclick="moban()">》并填写姓名和成绩，名单可以参考<a href="uploader/moban/16.rar"  target="_blank">16级登记表</a>、<a href="uploader/moban/17.rar"  target="_blank">17级登记表</a>。
                            <br><br>
                            第四步：导入成绩模板 <input type="file" id="cjfile" style="display: inline;">
                            <br><br>
                            最后一步：点击 <input type="button" value="确定上传" onclick="sub()">
                            <br><br>
                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>
                                    <tr>
                                        <th>序号</th>
                                        <th>学期</th>
                                        <th>科目</th>
                                        <th>班级</th>
                                        <th>学号</th>
                                        <th>姓名</th>
                                        <th>得分</th>
                                        <th>时间</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                	<?php
                                	$result2=xdb::getInstance()->getarray("select * from kaoshi as k,ksscore as ks where k.id=ks.kid and kid=".$result['id']." and ks.uid=".XXF_UID);
                                	$i=0;
                                	foreach ($result2 as $row){$i++;
                                	?>
                                    <tr class="<?php echo $i%2==0?"even":"odd";?> gradeA">
                                    	<td><?php echo $i;?></td>
                                        <td><?php echo $row['term']?></td>
                                        <td><?php echo $row['kcname']?></td>
                                        <td><?php echo $row['cname']?></td>
                                        <td><?php echo $row['sno']?></td>
                                        <td><?php echo $row['sname']?></td>
                                        <td><?php echo $row['score']?></td>
                                        <td><?php echo $row['atime']?></td>
                                        <td><input onclick="xg(<?php echo $row['id']?>,'<?php echo $row['score']?>')" type="button" value="修改"> <input onclick="del(<?php echo $row['id']?>)"  type="button" value="删除"></td>
                                    </tr>
                                	<?php 
                                	}
                                	?>
                                </tbody>
                            </table>
                            <?php }?>
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
             </div>
        </div>
        <!-- /#page-wrapper -->
  </div>
        <!-- DataTables JavaScript -->
<?php require_once 'bottom.php';?>
    <script src="sb2/vendor/datatables/js/jquery.dataTables.js"></script>
    <script src="sb2/vendor/datatables-plugins/dataTables.bootstrap.min.js"></script>
    <script src="sb2/vendor/datatables-responsive/dataTables.responsive.js"></script>
    <script>
    $(document).ready(function() {
        $('#dataTables-example').DataTable({
            responsive: true,
            "aaSorting": [[ 0, "desc" ]],
            "aLengthMenu": [ 50, 25, 10, 1]
        });
    });
    function moban(){
		$cid=$("#cid").val();
		$kcid=$("#kcid").val();
		if($cid=='请选择'||$kcid=='请选择'){
			$.xalert("请完成以上一二步");
			return;
		}
		open("kaoshiup/type/moban/cid/"+$cid+"/kcid/"+$kcid);
    }
    $cjfile=$("#cjfile").xxfile({
		url:"kaoshiup",
		accept:".xls",
		maxsize:3*1024*1024,
		autoup:false
	});
	function sub(){
		var stime=setTimeout(function(){
			sub();
		},5000);
		$cid=$("#cid").val();
		$kcid=$("#kcid").val();
		if($("#cjfile").val().length<2||$cid=='请选择'||$kcid=='请选择'){
			$.xalert("请检查上面步骤是否完成？");
			return ;
		}
		$.xloading(1);
		$cjfile.startup({
			data:{
				kid:<?php echo $result['id']?>,
				cid:$cid,
				kcid:$kcid,
				type:'up'
			},
			success:function(data){console.log(data);
				$.xloading(0);
				clearTimeout(stime);
				if(data==1){
					$.xalert("上传成功",function(){
						location.reload();
					});
				}
			}
		});
	}
	function xg(id,score){
		$.xconfirm("<input id='score' value='"+score+"'>",function(tf){
			if(tf){
				score=document.getElementById("score").value;
				var send=function(){
					$.xxpost("kaoshiup",{type:"xg",score:score,id:id},function(data){
						if(data==1){
							location.reload();
						}
					}).error(function(){send();});
				}
				send();
			}
		});
	}
	function del(id){
		$.xconfirm("确定要删除么？",function(data){
 			if(data){
				$.xloading(1);
				$.xtodb("del","ksscore",{},id,function(data){
					if(data==0){
						$.xloading(0);
						$.xalert("删除失败");
					}else{
						window.location.reload();
					}
				});
			} 
		});
	}
    </script>